package client.comm.baoding.ui

import androidx.lifecycle.Observer
import client.comm.baoding.BaseMiddleActivity
import client.comm.baoding.R
import client.comm.baoding.api.event.EventUserInfo
import client.comm.baoding.databinding.ActivityUpdateUserinfoBinding
import client.comm.baoding.ui.vm.UpdateUserInfoViewModel
import client.comm.commlib.toast.toast
import org.greenrobot.eventbus.EventBus

class UpdateUserInfoActivity :
    BaseMiddleActivity<UpdateUserInfoViewModel, ActivityUpdateUserinfoBinding>() {

    override fun getLayout(): Int {
        return R.layout.activity_update_userinfo
    }

    override fun initViewModel(): UpdateUserInfoViewModel = createViewModel()

//    var filed: String? = ""

    override fun initView() {
        super.initView()
        binding?.apply {
            event = this@UpdateUserInfoActivity
            vm = viewModel
            title = "修改用户名"

            var filed = intent.getStringExtra("filed")
            viewModel.name.value = filed

        }
    }

    override fun observerUI() {
        viewModel.call.observe(this, Observer {
            it?.apply {
                if (isSuccess) {
                    toast("操作成功")
                    EventBus.getDefault().post(EventUserInfo())
                    finish()
                }
            }
        })
    }

}